package pers.csw.lookBook.utils;

import com.google.gson.Gson;
import com.qiniu.common.QiniuException;
import com.qiniu.common.Zone;
import com.qiniu.http.Response;
import com.qiniu.storage.Configuration;
import com.qiniu.storage.UploadManager;
import com.qiniu.storage.model.DefaultPutRet;
import com.qiniu.util.Auth;
import com.qiniu.util.StringMap;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.swing.plaf.synth.Region;
import java.io.IOException;


public class QiNiuCloudUtil {
    private Logger logger = LoggerFactory.getLogger(this.getClass());
    public static final String accessKey = "X2dlSFPAWbR74nfUx_BujjwqYoYrgWfV5jCAPQal";
    public static final String secretKey = "vluQQ-I2rLpfjr9QA2IQ8XPsuz-NDzE6qoLXZhBV";
    public static final String bucket = "lookbook231";

    Auth auth  = Auth.create(accessKey,secretKey);
    String upToken = auth.uploadToken(bucket);
    // 构造一个带指定Zone对象的配置类
    Configuration cfg = new Configuration(Zone.zone2());
    //创建上传对象
    UploadManager uploadManager = new UploadManager(cfg);

    public Response upload(String key) throws IOException {
        String filePath = System.getProperty("user.home") + "\\Desktop\\novelData\\"+key+".json";
        System.out.println(filePath);
        try {
            return uploadManager.put(filePath,"novel_data/"+key,upToken);
        } catch (QiniuException e) {
            Response r = e.response;
            logger.info(r.toString());
            return r;
        }
    }

}
